package heima.lm.oschina.utils;

import android.content.Context;
import android.content.SharedPreferences;

import heima.lm.oschina.BaseApplication;
import heima.lm.oschina.constant.Constants;

/**
 * Created by herenxue on 2017/3/5.
 */

public class SpUtil {

    public static void saveBoolean(String name, boolean value) {
        SharedPreferences sp = getContext().getSharedPreferences(Constants.CONFIG_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    public static boolean getBoolean(String name, boolean defValue) {
        SharedPreferences sp = getContext().getSharedPreferences(Constants.CONFIG_NAME, Context.MODE_PRIVATE);
        return sp.getBoolean(name, defValue);
    }

    public static void saveInt(String name, int value) {
        SharedPreferences sp = getContext().getSharedPreferences(Constants.CONFIG_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    public static int getInt(String name, int defValue) {
        SharedPreferences sp = getContext().getSharedPreferences(Constants.CONFIG_NAME, Context.MODE_PRIVATE);
        return sp.getInt(name, defValue);
    }

    public static void saveString(String name, String value) {
        SharedPreferences sp = getContext().getSharedPreferences(Constants.CONFIG_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString(name, value);
        edit.commit();
    }

    public static String getString(String name, String defValue) {
        SharedPreferences sp = getContext().getSharedPreferences(Constants.CONFIG_NAME, Context.MODE_PRIVATE);
        return sp.getString(name, defValue);
    }

    public static Context getContext() {
        return BaseApplication.mApp;
    }

}
